package backend.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.commons.io.FileUtils;

public class ExFileUtil extends FileUtils {
	
	
	public static String getFileSuffix(File file){
		String fileName = file.getName();
		String suffix = fileName.substring(
				fileName.lastIndexOf('.') + 1, fileName.length());
		return suffix;
	}
	
	
	public static void ren(String renSuffix,File...file){
		if (file != null && file.length > 0) {
			for (int i = 0; i < file.length; i++) {
				if (file[i] == null)
					continue;
				File finishFile = new File(file[i].getAbsoluteFile() + renSuffix);
				file[i].renameTo(finishFile);
			}
		}
    }
	
	public static File mkDir(String targetDir) {
		if (targetDir == null || "".equals(targetDir)) {
			throw new IllegalArgumentException("destDir can not be blank");
		}
		File dir = new File(targetDir);
		if (!dir.exists()) {
			if (!dir.mkdirs()) {
				throw new RuntimeException(
						"System failed to create directory :(");
			}
		}
		return dir;
	}
	
	public static void appendSpace(File f) throws IOException{
		FileWriter writer = new FileWriter(f,true);
		writer.append("\n");
		writer.close();
	}

}
